<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>购物车</title>
		<link rel="stylesheet" href="__ADMIN__/static/index/css/common.css" />
		<link rel="stylesheet" href="__ADMIN__/static/index/css/shop_cart.css" />
		<script type="text/javascript" src="__ADMIN__/static/index/js/jquery.min.js"></script>
		<script type="text/javascript" src="__ADMIN__/static/index/js/common.js"></script>
		<style>
			.middle>.box>.sub:hover{
				cursor: pointer;
			}
		</style>
	</head>

	<body onload="loadCar(),checkChange()">
		<!--头部-->
			{include file='public/_header' /}
			<!--搜索栏-->
			{include file='public/_search' /}
			</div>
		<!--内容-->
		<!--内容-->
		<div class="middle">
			<div class="box">
				<table cellpadding="0" cellspacing="0" border="0">
					<thead>
						
						<tr>
							<th><label><input type="checkbox" class="checkAll" />全部</label></th>
							<th>商品信息</th>
							<th>数量</th>
							<th>单价</th>
							<th>金额</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{volist name='car' id='vo'}
							<tr id="2">
								<td><input type="checkbox" class="cbox" buy_id='{:$vo.goods_id}' style_id='{:$vo.style_id}' goods_num='{:$vo.goods_num}'  onchange="checkChange()"></td>
								<td>
									<img style="display:inline-block;width: 191px;height: 92px;" src="__ADMIN__{:$vo.goods_thumb}">
									<h4><a href="pro_details.html">{:$vo.goods_name}</a></h4><span class="color_sort">颜色分类 {:$vo.goods_color}</span></td>
								<td><span class="reduce" onclick="reduceNum(this)">-</span><input type="text" value="{:$vo.goods_num}" class="num" onblur="numChange(this)"><span class="add" onclick="addNum(this)">+</span></td>
								<td><span class="unit">{:substr($vo.goods_price,3)}</span></td>
								<td><span class="total_price">{:$vo.goods_num*(float)substr($vo.goods_price,3)}</span></td>
								<td><span><a href="javascript:void(0)">移入收藏夹</a></span><br><span class="del"><a href="javascript:void(0)" onclick="del(this)">删除</a></span></td>
							</tr>
						{/volist}
					</tbody>
					<script>
						$(document).on('click','.cbox',function(){
							if($(this).attr('flag')==1)
							{
								$(this).attr('class','cbox');
								$(this).attr('flag',0);
							}else
							{
								$(this).attr('class','cbox on');
								$(this).attr('flag',1);
							}
						})
						
						
						
						//点击减少商品个数
						$(document).on('click','.reduce',function(){
							
							var num = $(this).next('input').val();
							var unit = $(this).parent().siblings().find('.unit').text();
							var total = num*unit;
							$(this).parent().siblings().find('.total_price').text(total);
//							$(this).next('input').val(num);
						})
//						//点击增加商品个数
						$(document).on('click','.add',function(){
							var num = $(this).prev('input').val();
							var unit = $(this).parent().siblings().find('.unit').text();
							var total = num*unit;
							$(this).parent().siblings().find('.total_price').text(total);
						})
					</script>
					<tfoot>
						<tr>
							<td colspan="6">
								<span><label><input type="checkbox" class="checkAll" />全部</label></span>
								<span><a href="javascript:void(0)" onclick="dels()">删除</a></span>
								<span><a href="javascript:void(0)">移入收藏夹</a></span>
								<span><a href="javascript:void(0)">分享</a></span>
								<span>已选商品 <i id="choose_num">0</i>件</span>
								<span>合计 <i id="sum">0.00</i></span>
							</td>
						</tr>
					</tfoot>
				</table>
				<button style=" width: 200px;height: 60px;border: 0;background-color: #c8000b;color: #FFFFFF;font-family: 'microsoft yahei';float: right;margin-top: 20px;" type="submit" class="sub" id="submitorder" >结算</button>
				<script>
					$(document).on('click','.sub',function(){
						var on = $('.on');
						
						var brr = new Array();
						$.each(on,function(k,v){
							var buy_id = $(v).attr('buy_id');
							var style_id = $(v).attr('style_id');
							var goods_num = $(v).attr('goods_num');
							var arr = new Array();
							arr.push(buy_id);
							arr.push(style_id);
							arr.push(goods_num); 
							brr.push(arr);
						})
						var str = JSON.stringify(brr);
						$.post('{:url("index/car/confirmorder")}',{str:str},function(data){
							console.log(data);
							data = JSON.parse(data);
							if(data[0] == 40000)
							{
								window.location = '/index/car/suborder'+'?ordernum='+data[1];
							}
						})
						return false;
//						console.log(brr);
					})
				</script>
			</div>
		</div>
		<script>
			window.onerror=function(){return true;};
		</script>
		<script type="text/javascript" src="__ADMIN__/static/index/js/shop_cart.js"></script>
		<!--尾部-->
		{include file='public/_foot' /}
		
		
	</body>

</html>